package router

import (
	"blog/controller"
	"blog/middleware"

	"github.com/gin-gonic/gin"
)

func InitRouter() *gin.Engine {
	r := gin.Default()

	r.Use(middleware.Cors())
	r.Use(middleware.Logger())

	user := r.Group("/user")
	{
		user.POST("/register", controller.Register)
		user.POST("/login", controller.Login)
	}

	art := r.Group("/api")
	{
		art.POST("/article/add", controller.AddArticle)
		// art.POST("/article/upload", controller.UploadImage)
		art.GET("/article/:id", controller.GetArtInfo)
		art.GET("/article/list", controller.GetArtList)
		art.GET("/article/search", controller.SearchArticle)
		art.GET("/articlecate/:id", controller.GetCateArticle)
		art.PUT("/article/edit/:id", controller.EditArticle)
		art.DELETE("/article/delete/:id", controller.DeleteArticle)

		art.POST("/category/add", controller.AddCategory)
		art.GET("/category", controller.GetCategory)
		art.GET("/categoryid/:name", controller.GetCategoryId)
		art.PUT("/category/edit/:id", controller.EditCategory)
		art.DELETE("/category/delete/:id", controller.DelCategory)
	}
	pro := r.Group("/project")
	{
		pro.POST("/addpro", controller.CreateProject)
		pro.GET("/getproinfo/:id", controller.GetProjectInfo)
		pro.GET("/getpro", controller.GetProject)
		pro.PUT("/editpro/:id", controller.EditCategory)
		pro.DELETE("/delpro/:id", controller.DeleteProject)
	}
	return r
}
